package cn.xfdzx.android.apps.shop.presenter;

import cn.xfdzx.android.apps.shop.base.BasePresenter;
import cn.xfdzx.android.apps.shop.bean.BaseObjectBean;
import cn.xfdzx.android.apps.shop.bean.LiveInfoBeen;
import cn.xfdzx.android.apps.shop.bean.PushInfoBeen;
import cn.xfdzx.android.apps.shop.contract.CreateZhiboContract;
import cn.xfdzx.android.apps.shop.contract.ShopManagerContract;
import cn.xfdzx.android.apps.shop.model.CreateZhiboModel;
import cn.xfdzx.android.apps.shop.model.ShopManagerModel;
import cn.xfdzx.android.apps.shop.net.RxScheduler;
import io.reactivex.functions.Consumer;

/**
 * @author azheng
 * @date 2018/6/4.
 * Description：
 */
public class CreateZhiboPresenter extends BasePresenter<CreateZhiboContract.View> implements CreateZhiboContract.Presenter {

    private CreateZhiboContract.Model model;

    public CreateZhiboPresenter() {
        model = new CreateZhiboModel();
    }




    @Override
    public void liveInfo() {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.liveInfo()
                .compose(RxScheduler.<LiveInfoBeen>Flo_io_main())
                .as(mView.<LiveInfoBeen>bindAutoDispose())
                .subscribe(new Consumer<LiveInfoBeen>() {
                    @Override
                    public void accept(LiveInfoBeen bean) throws Exception {
                        mView.onLiveInfoSuccess(bean);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }

    @Override
    public void pushInfo(boolean is_yijian) {
        //View是否绑定 如果没有绑定，就不执行网络请求
        if (!isViewAttached()) {
            return;
        }
        mView.showLoading();
        model.pushInfo( )
                .compose(RxScheduler.<PushInfoBeen>Flo_io_main())
                .as(mView.<PushInfoBeen>bindAutoDispose())
                .subscribe(new Consumer<PushInfoBeen>() {
                    @Override
                    public void accept(PushInfoBeen bean) throws Exception {
                        mView.onPushInfoSuccess(bean,is_yijian);
                        mView.hideLoading();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        mView.onError(throwable);
                        mView.hideLoading();
                    }
                });
    }
}
